package com.jar.exercise.算法.leetcode;

public class Solution {

    public static void main(String[] args) {
        System.out.println(maxSubArray(new int[]{-3, 1, 5, -6, -4, 4,3}));
    }

    public static int maxSubArray(int[] nums) {
        int res = nums[0];
        int sum = 0;
        for (int num : nums) {
            if (sum > 0) {
                sum += num;
            } else {
                sum = num;
            }
            res = Math.max(res, sum);
        }
        return res;
    }
}
